import { createStore, applyMiddleware } from "redux";
import logger from "redux-logger";
import reduxPromise from "redux-promise";
import reduxThunk from "redux-thunk";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage"; //默认是本地存储

//汇总的总reducer
import reducer from "./reducer";

let MiddlewareArr = [reduxPromise, reduxThunk];

if (process.env.NODE_ENV === "development") {
  MiddlewareArr.push(logger);
}

const persistConfig = {
  key: "root",
  storage,
  blacklist: ["UserReducer"],
};

const myPersistReducer = persistReducer(persistConfig, reducer);

const store = createStore(myPersistReducer, applyMiddleware(...MiddlewareArr));

export const persistor = persistStore(store);

export default store;
